package com.itheima.stock.controller;


import com.itheima.stock.pojo.entity.SysUser;
import com.itheima.stock.service.UserService;
import com.itheima.stock.vo.req.LoginReqVo;
import com.itheima.stock.vo.resp.LoginRespVo;
import com.itheima.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "接口服务")
@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService userService;

@ApiOperation("根据用户名查找用户")
@ApiImplicitParams({
        @ApiImplicitParam(name = "userName",value = "用户名",dataType = "string",required = true,type = "path")
})
    @GetMapping("/user/{userName}")
    public SysUser getUserByUserName(@PathVariable("userName") String userName) {//name查人

        SysUser sysUser = userService.findByUsername(userName);
        return sysUser;
    }
    @ApiOperation("登录")
    @PostMapping("/login")
    public R<LoginRespVo> login(@RequestBody LoginReqVo vo) {//登陆
        return userService.login(vo);
    }
    @ApiOperation("验证码")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode() {
        return userService.getCaptchaCode();
    }



//    @PostMapping("/login")
//    public  R<SysUser>

}
